package com.zhanjixun.springcloud.demo.userprovider.service.impl;

import com.zhanjixun.springcloud.demo.userprovider.entities.SysUser;
import com.zhanjixun.springcloud.demo.userprovider.entities.SysUserExample;
import com.zhanjixun.springcloud.demo.userprovider.mapper.SysUserMapper;
import com.zhanjixun.springcloud.demo.userprovider.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author :zhanjixun
 * @date : 2019/8/25 13:07
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public boolean addUser(SysUser sysUser) {
        return sysUserMapper.insert(sysUser) == 1;
    }

    @Override
    public SysUser queryUser(String account) {
        SysUserExample example = new SysUserExample();
        example.createCriteria().andAccountEqualTo(account);
        List<SysUser> sysUsers = sysUserMapper.selectByExample(example);
        return sysUsers.stream().findFirst().orElse(null);
    }

    @Override
    public SysUser queryUser(String account, String password) {
        SysUserExample example = new SysUserExample();
        example.createCriteria().andAccountEqualTo(account).andPasswordEqualTo(password);
        List<SysUser> sysUsers = sysUserMapper.selectByExample(example);
        return sysUsers.stream().findFirst().orElse(null);
    }
}
